<template>
	<view class="beijingse">
		<u-popup :show="scshow" @close="scclose" mode="center" :round="15">
			<view class="mainpadding">
				<view class="xiaohei bigtext fonweight textcenter">提示</view>
				<view class="xiaohei titletext nofonweight textcenter margin_top4">确认要退出登录么？</view>
				<view class="flexcenter margin_top6">
					<view class="quxibtn flexcenter margin_right3" @click="scclose">取消</view>
					<view class="quedbtn flexcenter">确定</view>
				</view>
			</view>
		</u-popup>
		<!-- 头部 -->
		<u-sticky>
			<view class="dingbu mainpadding2"  v-if="!is_login">
				<view class="" :style="{paddingTop:menutop+'rpx'}">
					<view class="flexbetween margin_top5" @click="jumper('/pages/login/login')">
						<view class="flexleft">
							<view class="touxiang margin_right2">
								<image src="@/static/image/system/weidenglu.png" mode=""></image>
							</view>
							<view class="bigtext xiaohei fonweight">未登录,点击登录</view>
						</view>
						<u-icon name="arrow-right" color="#C8C8C8"></u-icon>
					</view>
				</view>
			</view>
			<view class="dingbu mainpadding2" v-else >
				<view class="" :style="{paddingTop:menutop+'rpx'}">
					<view class="flexbetween margin_top5" @click="jumper('/pages/mypage/zhanghaoxq')">
						<view class="flexleft">
							<view class="touxiang margin_right2">
								<image :src="userInfo.avatar_text" mode=""></image>
							</view>
							<view class="bigtext xiaohei fonweight">{{userInfo.nickname}}</view>
						</view>
						<u-icon name="arrow-right" color="#C8C8C8"></u-icon>
					</view>
				</view>
			</view>
		</u-sticky>
		<view class="mainpadding">
			<!-- <view class="mainpadding ffffff radius flexbetween" @click="tzgywm(1)">
				<view class="flexleft" >
					<view class="xicon margin_right2">
						<image src="../../static/image/system/mxdx.png" mode=""></image>
					</view>
					<view class="sanshier xiaohei nofonweight">使用导向</view>
				</view>
				<u-icon name="arrow-right" color="#C8C8C8"></u-icon>
			</view> -->
			<view class="mainpadding ffffff radius flexbetween margin_top" @click="tzgywm(4)">
				<view class="flexleft" >
					<view class="xicon margin_right2">
						<image src="../../static/image/system/mxdx.png" mode=""></image>
					</view>
					<view class="sanshier xiaohei nofonweight">服务协议</view>
				</view>
				<u-icon name="arrow-right" color="#C8C8C8"></u-icon>
			</view>
			<view class="mainpadding ffffff radius flexbetween margin_top" @click="tzgywm(3)">
				<view class="flexleft">
					<view class="xicon margin_right2">
						<image src="../../static/image/system/mxdx.png" mode=""></image>
					</view>
					<view class="sanshier xiaohei nofonweight">隐私政策</view>
				</view>
				<u-icon name="arrow-right" color="#C8C8C8"></u-icon>
			</view>
			<view class="huibtnd flexcenter" v-if="is_login" @click="outlogin">退出登录</view>
		</view>
		<tabbardi :current="1"></tabbardi>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				menutop: 0,
				scshow: false,
				is_login: false,
				userInfo: null,
			}
		},
		onLoad() {
			this.menutop = uni.getMenuButtonBoundingClientRect().top * 2
		},
		onShow() {
			this.is_login = httpRequest.checkIsLogin();
			if (this.is_login) {
				this.init()
			}else{
				this.userInfo = null
			}
		},
		onShareAppMessage() {
			let _this = this
			return {
				title: "光源太阳能",
				path: "pages/index/index"
			}
		},
		onShareTimeline: function() {
			return {
				title: "光源太阳能",
				path: "pages/index?code=" + uni.getStorageSync("yqm"),
			}
		},
		methods: {
			outlogin() {
				httpRequest.modal('退出登录', '请确认是否退出登录', true, (res) => {
					if (res) {
						uni.clearStorageSync()
						httpRequest.toast("退出登录成功")
						this.is_login = false
						this.userInfo = null
					}
				})
			},
			init() {
				httpRequest.request('/api/user/index', 'GET', {}).then(res => {
					this.userInfo = res.data
				})
			},
			tzgywm(i) {
				if (!httpRequest.checkIsLogin()) {
					uni.navigateTo({
						url: "/pages/login/login"
					})
					return false
				}
				uni.navigateTo({
					url: '/pages/mypage/shiyongxd?id=' + i
				})
			},
			scclose() {
				this.scshow = false
				// console.log('close');
			},
			jumper(url){
				if (!httpRequest.checkIsLogin()) {
					uni.navigateTo({
						url: "/pages/login/login"
					})
					return false
				}
				uni.navigateTo({
					url:url
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.huibtnd {
		margin-top: 170rpx;
		width: 100%;
		height: 94rpx;
		background: #EFEFEF;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
		font-size: 32rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		color: #333333;
	}

	.xicon {
		width: 36rpx;
		height: 36rpx;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.dingbu {
		background-size: 100% 100%;
		width: 100%;
		box-sizing: border-box;
		background-image: url('../../static/image/system/wd.png');
	}

	.touxiang {
		width: 110rpx;
		height: 110rpx;
		border-radius: 50%;

		image {
			border-radius: 50%;
			width: 100%;
			height: 100%;
		}
	}
</style>